package com.milhouz.bomberrokon.sprite;

import com.stickycoding.Rokon.Texture;

public class DestructableObjSprite extends SolidObject {

	private static int sAnimeDestroy[] = null;
	private static final int ANIM_FRAME_TIME = 50;

	private Texture exploseTexture;
	boolean explose = false;

	public DestructableObjSprite(int x, int y, Texture objTexture, Texture exploseTexture, int nbTiles) {
		super(x, y, objTexture);
		this.exploseTexture = exploseTexture;
		initAnimeDestroy(nbTiles);
	}

	public void explose() {
		explose = true;
		setTexture(exploseTexture);
		this.animateCustom(sAnimeDestroy, ANIM_FRAME_TIME, 2, false);
	}

	public boolean isFinished() {
		if (explose && !this.isAnimating()) {
			this.markForRemoval();
			return true;
		}
		return false;
	}

	private void initAnimeDestroy(int nbTiles) {
		if (sAnimeDestroy == null) {
			sAnimeDestroy = new int[nbTiles];
			for (int i = 1; i <= nbTiles; i++) {
				sAnimeDestroy[i - 1] = i;
			}
		}
	}
}
